<?php

!defined('IN_APP') && exit('Access Denied');

class userfieldmodel extends modelbase {


	function findByName($fieldName){
		$fieldItem = $this->collection->findOne(array("name" => $fieldName));
		return $fieldItem;
	}

    function findAll( $query = array() ) {
        $userfieldlist = array();
        $cursor = $this->collection->find($query)->sort(array('displayorder'=>1)); 
        foreach ($cursor as $userfield){
		    $userfield['default'] && $userfield['defaults'] = explode(',' ,$userfield['default']);
            $userfieldlist[] = $userfield;
        }
        return $userfieldlist;
    }
    
	function order($orderstr) {
	     $orders=explode(',',$orderstr);
	     $count=count($orders);
	     for($i=0;$i<$count;$i++) {
	         $this->update(array('id'=>intval($orders[$i]) ),array('displayorder'=>$i));
	     }
	 }


}

